<!DOCTYPE html>
<html lang="en-us" id="extr-page">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
</head>
<body>

<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>

<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../global/js/common.js"></script>

<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
        <input type="hidden" id="id" name="id" />
           <div class="form-group">
                <label class="col-md-2 control-label">商品</label>
                <div class="col-md-10">
                    <select id="goodsId" class="form-control" name="goodsId">
                    	<option value="">请选择</option>
                    </select>
                </div>
            </div>
           <div class="form-group">
                <label class="col-md-2 control-label">商城类型</label>
                <div class="col-md-10" style="width: 120px">
                 <select class="form-control input-sm" name="type" id="type">
                 <option value="0">积分商城</option>
                 <option value="1" >红包商城</option> 
                 <option value="2" >礼品劵商城</option>
                 </select>
            </div>
            </div>
            <div class="form-group">
                <label class="col-md-2 control-label">状态</label>
                <div class="col-md-10" style="width: 120px">
                 <select class="form-control input-sm" name="state" id="state">
                 <option value="0">未审核</option>
                 <option value="1" >已审核</option> 
                 </select>
            </div>
            </div>
          <div class="form-group">
           <label class="col-md-2 control-label" id="integrals">积分</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="积分" type="text" name="integral" id="integral"  />
           </div>
          </div>
          <div class="form-group">
           <label class="col-md-2 control-label" id="redPackages">红包</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="红包" type="text" name="redPackage" id="redPackage" />
           </div>
          </div>
          <div class="form-group">
           <label class="col-md-2 control-label" id="giftCertificates">礼品劵</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="礼品劵" type="text" name="giftCertificate" id="giftCertificate" />
           </div>
          </div>
           <div class="form-group">
           <label class="col-md-2 control-label">库存</label>
           <div class="col-md-10">
            <input class="form-control" placeholder="库存" type="text" name="stock" id="stock" />
           </div>
	       </div>
	        <div class="form-group">
	           <label class="col-md-2 control-label">排序</label>
	           <div class="col-md-10">
	            <input class="form-control" placeholder="排序" type="text" name="sort" id="sort" />
	           </div>
	          </div>
        
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='exchangeList.html'">返回</button>
                        <button id="submitbtn" class="btn btn-primary" type="submit" onclick="add()"><i class="fa fa-save"></i> 保存</button>
                    </div>
                </div>
            </div>

        </fieldset>
    </form>
</div>
<!-- <script type="text/javascript" src="../../global/layui/layui.js"></script> -->
<script type="text/javascript">
    /* layui.use('layer', function () {
        var layer = layui.layer;
    }); */
    var id = getUrlParam("id");
    $.ajax({
        type: 'get',
        url: '/clyjExchangeMall/getExchangeList/',
        data:{id:id},
        contentType: "application/json; charset=utf-8",
        async: false,
        success: function (data) {
        	console.info(data);
        	for(var i=0;i<data.length;i++){
        		$("#goodsId").append("<option value='"+data[i].goodsId+"'>"+data[i].goodsName+"</option>");
        	}
        }
    });
    $('#form').bootstrapValidator();
    function add() {
    	 // 表单验证
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }
        formdata = $("#form").serializeObject();
        $.ajax({
        	type: 'post',
            url: '/clyjExchangeMall/saveExchange/',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
            	console.log(data);
            	if(data.code=="success"){
            		layer.msg("新增成功", {shift: -1, time: 1000}, function () {
                        location.href = "exchangeList.html";
                    });
            	}
            		layer.msg("新增失败", {shift: -1, time: 1000}, function () {
                        location.href = "exchangeList.html";
                    });
            	
            }
        });
    }
</script>
</body>
</html>